package com.oriental.manage.controller.reserve.report;

import com.oriental.manage.core.paging.Pagination;
import com.oriental.manage.core.response.ResponseDTO;
import com.oriental.manage.service.reserve.BankReserveReportService;
import com.oriental.reserve.model.report.BankReportModelDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Author: Yang xp
 * Date: 2017/3/14
 * Time: 9:55
 * Desc：
 */
@Slf4j
@Controller
@RequestMapping("/reserve/bank/report")
public class BankReserveReportController {

    @Autowired
    private BankReserveReportService bankReserveReportService;

    @RequestMapping("/init")
    public String init(){
        return "reserve/report/searchBankReport";
    }

    @RequestMapping("/toAdd")
    public String toAdd(){
        return "reserve/report/addBankReport";
    }

    @RequestMapping("/search")
    @ResponseBody
    public ResponseDTO<Pagination<BankReportModelDto>> search(@RequestBody BankReportModelDto bankReportModelDto){
        ResponseDTO<Pagination<BankReportModelDto>> responseDTO = new ResponseDTO<>();
        try {
            log.info("查询银行备付金信息：{}",bankReportModelDto);
            bankReserveReportService.searchBankReport(responseDTO,bankReportModelDto);
        }catch (Exception e){
            log.error("银行备付金报表查询失败:",e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("查询失败");
        }
        return responseDTO;
    }

    @RequestMapping("/create")
    @ResponseBody
    public ResponseDTO<String> bankReportPush(@RequestBody BankReportModelDto bankReportModelDto){
        ResponseDTO<String> responseDTO = new ResponseDTO<>();
        try {
            log.info("创建银行备付金信息：{}",bankReportModelDto);
            bankReserveReportService.bankReportPush(responseDTO,bankReportModelDto);
        }catch (Exception e){
            log.error("银行备付金报表生成失败:",e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("生成失败");
        }
        return responseDTO;
    }

    @RequestMapping("/audit")
    @ResponseBody
    public ResponseDTO<String> auditReportPush(@RequestBody BankReportModelDto bankReportModelDto){
        ResponseDTO<String> responseDTO = new ResponseDTO<>();
        try {
            log.info("审核银行备付金信息：{}",bankReportModelDto);
            bankReserveReportService.auditBankReport(responseDTO,bankReportModelDto);
        }catch (Exception e){
            log.error("银行备付金报表审核失败:",e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("审核失败");
        }
        return responseDTO;
    }

    @RequestMapping("/check")
    @ResponseBody
    public ResponseDTO<String> pullCheckResult(@RequestBody BankReportModelDto bankReportModelDto){
        ResponseDTO<String> responseDTO = new ResponseDTO<>();
        try {
            log.info("获取银行备付金勾稽信息：{}",bankReportModelDto);
            bankReserveReportService.pullCheckResult(responseDTO,bankReportModelDto);
        }catch (Exception e){
            log.error("银行备付金报表获取勾稽失败:",e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("获取失败");
        }
        return responseDTO;
    }



}
